<template>
	<view class="index1_content">

		<!-- 导航栏 -->
		<view class="search-header">
			<view @click="handeleTo">
				<image style="width: 15rpx;height: 30rpx;" src="@/static/index2/index7.png" mode=""></image>
			</view>
			<view style="color: #FFFFFF;font-size: 32rpx;margin-right: 10rpx; text-align: center;"
				:style="{'font-size':lang=='zh'?'32rpx':'24rpx'}">{{$t('出入库记录')}}</view>
			<view></view>
		</view>



		<!-- 模块 -->
		<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Ys1" refresher-enabled="true"
			:refresher-triggered="freshIsShow" @scrolltolower="lower" @refresherrefresh="fresh"
			@refresherrestore="store"
			refresher-background="background: linear-gradient(90deg, #5695FF -2%, #44D1D4 105%);">
			<view :class="codeType?'Ant-block':'Ant-block-class'" v-for="(item,index) in stockList" :key="index">

				<view class="Ant-block1">
					<view style="color: #005EAC;font-size: 24rpx;">{{$t('仓库编码')}}：
						{{String(item.id).padStart(6,"0")}}
					</view>
					<!-- <div class="flex">
						<view class="Ant-block2" @click="handeleRemove(item,index)">{{$t("删除")}}</view>
						<view class="Ant-block2" @click="item.slide=!item.slide" style="margin-left: 16rpx;">
							{{item.slide?$t("收起"):$t("展开")}}{{$t("详情")}}
						</view>
					</div> -->
				</view>
				<view class="Ant-block3">
					<view class="section-label flex">
						<view style="min-width: 120rpx;">{{$t('货物名称')}}：</view>
						<view style="flex: 1;"> {{langKey(item,"goods")}}</view>
					</view>
					<view class="section-label">
						{{$t('所属仓库')}}： {{langKey(item.warehouse,"name")}}
					</view>
					<view class="section-label">
						{{$t('所属货位')}}： {{langKey(item.storage,"name")}}
					</view>
					<view style="border-top: 1px dashed #D8D8D8;margin-top: 20rpx;"></view>
					<view style="font-size: 24rpx;color: #1D1D1D;margin-top: 20rpx;padding: 0 30rpx;">
						{{$t('入库数量')}}：{{item.number}}
					</view>
					<view style="font-size: 24rpx;color: #1D1D1D;margin-top: 20rpx;padding: 0 30rpx;">
						{{$t('单件重量(kg)')}}：{{item.weight}}
					</view>
					<view style="font-size: 24rpx;color: #1D1D1D;margin-top: 20rpx;padding: 0 30rpx;">
						{{$t('单件体积(m³)')}}：{{item.volume}}
					</view>
					<view style="font-size: 24rpx;color: #1D1D1D;margin-top: 20rpx;padding: 0 30rpx;">
						{{$t('入库时间')}} {{item.create_at}}
					</view>
					<view v-if="item.slide">
						<view style="margin-top:20rpx;border-top: 1rpx solid #ddd"></view>
						<view style="font-size: 24rpx;color: #1D1D1D;margin-top: 20rpx;padding: 0 30rpx;">
							{{$t('总重量(kg)')}}：{{item.number*item.weight}}
						</view>
						<view style="font-size: 24rpx;color: #1D1D1D;margin-top: 20rpx;padding: 0 30rpx;">
							{{$t('总体积(m³)')}}：{{item.number*item.volume}}
						</view>
					</view>

					<view style="border-top: 1px dashed #D8D8D8;margin-top: 24rpx;"></view>
				</view>
			</view>

		</scroll-view>


		<!-- 顶部背景色 -->
		<image style="width: 750rpx;height: 690rpx;position: absolute;top: 0;z-index: 1;"
			src="@/static/index2/20241101130857.png" mode=""></image>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				p_id: "",
				lang: uni.getStorageSync("lang"),
				currentItem: {},
				wareHouseInIsShow: false,
				wareHouseOutIsShow: true,
				value: '',
				codeType: false,
				border: false,
				scrollTop: 0, //高度
				freshIsShow: true, //下拉加载
				page: 1, //页数
				total: 0, //总条数
				stockList: [], //数据
				stock_append_count: 1, //补货
			}
		},
		onLoad(e) {
			if (e.id) {
				this.p_id = e.id
			}
			this.stock_lists();
		},
		methods: {
			wareHouseIn(item, index) {
				this.currentItem = item
				this.wareHouseInIsShow = true;
			},
			wareHouseOut(item, index) {
				this.currentItem = item
				this.wareHouseOutIsShow = true;
				this.transport()
			},
			stock_lists() {
				this.$u.api.basic.stock_lists_child({
					user_id: uni.getStorageSync("user_id"),
					p_id: this.p_id,
					page: 1,
					limit: 9999
				}).then(res => {
					res.forEach(item => {
						item.slide = false
					})
					this.stockList = res;
				})
			},
			// 删除
			handeleRemove(item, index) {
				uni.showModal({
					title: this.$t('确认删除'),
					content: this.$t('是否确认删除当前'),
					confirmText: this.$t('确认'),
					cancelText: this.$t('取消'),
					success: res => {
						if (res.confirm) {
							this.$u.api.basic.stock_del({
								id: item.id
							}).then(res => {
								uni.showToast({
									title: this.$t("操作成功")
								})
								this.stockList.splice(index, 1)
							})

						} else if (res.cancel) {}
					}
				});
			},
			// 获取数据
			getData() {
				console.log('获取数据');
				setTimeout(() => {
					this.freshIsShow = false
				}, 2000)
			},
			// 返回上一页
			handeleTo() {
				uni.navigateBack()
			},
			// 下拉刷新复位
			store() {
				this.freshIsShow = false
			},
			// 下拉刷新触发
			fresh() {
				this.page = 1
				this.freshIsShow = true
				this.getData()
			},
			// 触底加载
			lower() {
				// 触底判断总条数不等于当前数据的条数则获取数据
				if (this.total != this.arr.length) {
					this.getData()
				}
			},
			//补货
			stock_append() {
				if (!this.stock_append_count || this.stock_append_count < 1) {
					return this.toast(this.$t("请输入正确的数量"))
				}
				this.$u.api.basic.stock_append({
					user_id: uni.getStorageSync("user_id"),
					p_id: this.currentItem.id,
					number: parseFloat(this.stock_append_count)
				}).then(res => {
					this.toast(this.$t("操作成功"))
					this.stock_lists()
					this.wareHouseInIsShow = false;
				})
			},
			//运输
			transport() {
				uni.navigateTo({
					url: `/pages/release/transport/form?type=2&workTransport=${JSON.stringify(this.currentItem)}`
				})
			}
		}
	}
</script>

<style scoped>
	.w-full {
		width: 100% !important;
		margin-bottom: 16rpx;
	}
	
	.scroll-Ys1 {
		margin-top: 24rpx;
		z-index: 2;
		width: 690rpx;
		height: calc(100vh - 270rpx);
	}

	.Ant-block6 {
		width: 30%;
		height: 60rpx;
		border-radius: 60rpx;
		font-size: 22rpx;
		color: #FFFFFF;
		background: #5282E6;
		text-align: center;
		line-height: 60rpx;
		display: inline-block;
		padding: 0 20rpx;
	}

	.Ant-block5 {
		min-width: 305rpx;
		height: 60rpx;
		border-radius: 60rpx;
		font-size: 22rpx;
		color: #FFFFFF;
		background: #FF5D5D;
		text-align: center;
		line-height: 60rpx;
		display: inline-block;
		padding: 0 20rpx;
	}

	.Ant-block4 {
		width: 100%;
		height: 60rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 24rpx;
	}

	.Ant-block3 {
		width: 100%;
		min-height: 426rpx;
		border-radius: 32rpx;
		background: #FFFFFF;
		padding: 22rpx 0 24rpx 0;
		box-sizing: border-box;
	}

	.Ant-block2 {
		min-width: 133rpx;
		height: 48rpx;
		font-size: 22rpx;
		color: #005EAC;
		background: #FFFFFF;
		border-radius: 48rpx;
		text-align: center;
		line-height: 48rpx;
		display: inline-block;
		padding: 0 20rpx;
	}

	.Ant-block1 {
		width: 100%;
		min-height: 72rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.Ant-block {
		margin-top: 24rpx;
		z-index: 2;
		width: 690rpx;
		min-height: 498rpx;
		border-radius: 32rpx;
		background: linear-gradient(90deg, #CCD6FF -2%, #4A70FC 105%);
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.Ant-block-class {
		margin-top: 24rpx;
		z-index: 2;
		width: 690rpx;
		min-height: 498rpx;
		border-radius: 32rpx;
		background: linear-gradient(91deg, #FCF9E8 0%, #F2C376 95%);
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.ent-search-right {
		flex: 1;
		min-width: 100rpx;
		height: 70rpx;
		text-align: center;
		line-height: 70rpx;
		font-size: 24rpx;
		color: #FFFFFF;
		flex-shrink: 0;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.Ant-search {
		z-index: 2;
		width: 690rpx;
		min-height: 70rpx;
	}

	.ent-search {
		background-color: #FFFFFF;
		width: 100%;
		height: 70rpx;
		border-radius: 12rpx;
		padding: 0 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.search-header {
		z-index: 2;
		width: 690rpx;
		height: 133rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 40rpx;
	}

	.index1_content {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		background-color: #F1F2F4;
		height: 100vh;
	}

	.title {
		text-align: center;
		font-size: 28rpx;
		font-weight: bold;
	}

	.in-content {
		padding: 30rpx;
	}

	.label {
		margin-top: 30rpx;
		font-weight: bold;
		margin-bottom: 16rpx;
		margin-top: 50rpx;
	}

	.in-count {
		font-size: 30rpx;
		width: 100%;
		margin-right: 5%;
		background-color: #f5f5f5;
		height: 100rpx;
		padding: 0 30rpx;
	}

	.unit {
		flex-shrink: 0;
	}

	.flex2 {
		display: flex;
		align-items: center;
	}

	.btn-group {}

	.btn-group .btn {
		background-color: #5282E6;
		color: #fff;
		width: 45%;
		display: flex;
		align-items: center;
		justify-content: center;
		height: 80rpx;
		border-radius: 50rpx;
	}

	.default {
		color: #1d1d1d !important;
		border: 1rpx solid #ddd;
		box-sizing: border-box;
		background: none !important;
	}

	.between {
		display: flex;
		justify-content: space-between;
	}

	.section-label {
		padding: 10rpx 30rpx;
		font-size: 24rpx;
	}
</style>